
// Definition for a binary tree node.
function TreeNode(val, left, right) {
    this.val = (val===undefined ? 0 : val)
    this.left = (left===undefined ? null : left)
    this.right = (right===undefined ? null : right)
}

/**
 * @param {TreeNode} root
 * @return {string[]}
 */
var binaryTreePaths = function(root) {
  let result = [], stack = [];
  function printPath(node, arr) {
    let tempArr = [...arr];
    tempArr.push(node.val);
    if(!node.left && !node.right) {
      result.push(tempArr.join("->"));
    } else {
      if(node.left) printPath(node.left, tempArr);
      if(node.right) printPath(node.right, tempArr);
    }
  }
  printPath(root, []);
  return result;
};
